package br.edu.fanor.processabatch.utils;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;

import br.edu.fanor.processabatch.entity.Dependente;
import br.edu.fanor.processabatch.entity.Servidor;
import br.edu.fanor.processabatch.entity.VinculoFuncional;

public class EntitysFactoryUtils {
	
	private static Integer idServidor = 0;
	private static Integer idDependente = 0;
	private static Integer idVinculo = 0;
	
	
	public static Servidor getServidor(){
		
		Servidor servidor = new Servidor();
		servidor.setId(getIdServidor());
		servidor.setNome(geraNomes());
		servidor.setEndereco(geraNomes()+geraNomes());
		servidor.setTelefone(geraTelefone());
		
		return servidor;
		
	} 
	
	public static Dependente getDependente(Servidor servidor){
		
		Dependente dependente = new Dependente();
		dependente.setId(getIdDependente());
		dependente.setServidor(servidor.getId());
		dependente.setNome(geraNomes());
		dependente.setDataNascimento(geraData());
		
		return dependente;
	}
	
	public static VinculoFuncional getVinculoFuncional(Servidor servidor){
		
		VinculoFuncional vinculo = new VinculoFuncional();
		vinculo.setId(getIdVinculo());
		vinculo.setServidor(servidor.getId());
		vinculo.setCargo(geraCargos());
		vinculo.setDataInicio(geraData());
		vinculo.setDataFim(geraData());
		
		return vinculo;
	}
	
	private static String geraCargos(){
		String[] cargos = {"medico", "advogado", "analista de sistemas", "engenheiro",
				"enfermeiro", "carpinteiro", "zelador", "secretaria", "gerente"};
		
		return cargos[new Random().nextInt(8)];
	}
	
	private static String geraNomes(){
		
		Random random = new Random();
		String letras[] = {"a", "b", "c", "d", "e", "f", "g", "h",
				"i", "j","k", "l", "m", "n", "o", "p", "q", "r", "s", 
				"t", "u", "v", "w", "x", "y", "z", " "};
		
		return letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)]
				+letras[random.nextInt(26)]+letras[random.nextInt(26)]+letras[random.nextInt(26)];
	}
	
	private static String geraTelefone(){
		Random random = new Random();

		return "("+random.nextInt(9)+random.nextInt(9)+") "+random.nextInt(9)+random.nextInt(9)
				+random.nextInt(9)+random.nextInt(9)+"-"+random.nextInt(9)+random.nextInt(9)
				+random.nextInt(9)+random.nextInt(9);
	}
	
	public static Date geraData(){
		
		Random random = new Random();
		
		String[] dias = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"
				, "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"
				,"25", "26", "27", "28"};
		String[] mes = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
		
		String ano = random.nextInt(9)+""+random.nextInt(9)+""+random.nextInt(9)+""+random.nextInt(9);
				
		return new GregorianCalendar(Integer.parseInt(dias[random.nextInt(27)]),
				Integer.parseInt(mes[random.nextInt(11)]), Integer.parseInt(ano)).getTime();
	}
	
	public static void main(String[] args) {
		geraData();
	}
	
	public static Integer getIdServidor(){
		return ++idServidor;
	}
	
	public static Integer getIdDependente(){
		return ++idDependente;
	}
	
	public static Integer getIdVinculo(){
		return ++idVinculo;
	}	

}
